package com.rulin.asp.sso.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.rulin.asp.sso.entity.Menu;
import com.rulin.asp.sso.entity.User;
import com.rulin.asp.sso.mapper.MenuMapper;
import com.rulin.asp.sso.mapper.UserMapper;

@Service
public class AuthService {

	@Autowired
	private MenuMapper menuMapper;
	
	@Autowired
	private UserMapper userMapper;
	
	/**
	 * 根据用户名获取首页菜单栏
	 * @param userAccount
	 * @return
	 */
	public List<Menu> getMenusByUser(String userAccount){
		User user = userMapper.selectByUserAccount(userAccount);
		String userType = user.getUserType();
		if("1".equals(userType)){//如果是教师
			Integer level = 2;
			List<Menu> list = menuMapper.selectByAuthLevel(level);
			return list;
		}else {//如果是管理员
			Integer level = 1;
			List<Menu> list = menuMapper.selectByAuthLevel(level);
			return list;
		}
		
	}
}
